//
//  DragTableView.m
//  TableViewDrag
//
//  Created by max on 2018/10/30.
//  Copyright © 2018年 max. All rights reserved.
//

#import "DragTableView.h"

@interface DragTableView() <UITableViewDelegate, UITableViewDataSource>

@end

@implementation DragTableView

- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style {
    if (self = [super initWithFrame:frame style:style]) {
        self.dataSource = self;
        self.delegate = self;
        [self registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
        self.tableFooterView = [UIView new];
    }
    return self;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.textLabel.text = self.dataArray[indexPath.row];
    return cell;
}


- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}

- (void)setDataArray:(NSMutableArray *)dataArray {
    _dataArray = dataArray;
    [self reloadData];
}



#pragma mark - Public Methods
- (UITableViewCell *)selectCellAtIndexPath:(NSIndexPath *)seletIndexPath {
    UITableViewCell *cell = [self cellForRowAtIndexPath:seletIndexPath];
    return cell;
}

@end
